package com.eco.fanliapp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.dao.AppMessageMapper;
import com.eco.fanliapp.entity.AppMessage;
import com.eco.fanliapp.service.IAppMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AppMessageServiceImpl extends ServiceImpl<AppMessageMapper, AppMessage> implements IAppMessageService {

    @Autowired
    private AppMessageMapper appMessageMapper ;

    /**
     *  新写入数据库记录,app_message
     *
     * @param message
     */
    @Override
    public ServerResponse<AppMessage> insert(AppMessage message) {
        int insert = appMessageMapper.insert(message);
        if (insert == 1){
            AppMessage appMessage = appMessageMapper.selectByMessageCode(message.getMessageCode());
            return ServerResponse.createBySuccess("增加成功",appMessage);
        }
        return ServerResponse.createByErrorMessage("增加失败");
    }


    /**
     * 根据消息代号更改消息内容
     * @param message
     * @return
     */
    @Override
    public ServerResponse<AppMessage> updateByMessageCode(AppMessage message) {

        int update = appMessageMapper.updateByMessageCode(message);
        if (update == 1){
            AppMessage appMessage = appMessageMapper.selectByMessageCode(message.getMessageCode());
            return ServerResponse.createBySuccess("更改成功",appMessage);
        }
        return ServerResponse.createByErrorMessage("更改失败");
    }

    /**
     *  根据指定消息代号获取一条数据库记录,app_message
     *
     * @param messageCode
     */
    @Override
    public ServerResponse<AppMessage> selectByMessageCode(String messageCode) {
        AppMessage appMessage = appMessageMapper.selectByMessageCode(messageCode);
        if (appMessage !=null){
            return ServerResponse.createBySuccess("查询成功",appMessage);
        }
        return ServerResponse.createByErrorMessage("查询失败");
    }


}
